﻿// -----------------------------------------------------------------------
// <copyright file="Pixel.cs" company="Hewlett-Packard">
// TODO: Update copyright text.
// </copyright>
// -----------------------------------------------------------------------

namespace ImageProcessing.Entities
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    /// <summary>
    /// Pixel class
    /// </summary>
    public class Pixel
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="Pixel"/> class.
        /// </summary>
        /// <param name="red">The red.</param>
        /// <param name="green">The green.</param>
        /// <param name="blue">The blue.</param>
        public Pixel(double red, double green, double blue)
        {
            this.Red = red;
            this.Green = green;
            this.Blue = blue;
            byte tempR = (byte)red;
            byte tempG = (byte)green;
            byte tempB = (byte)blue;
            byte one = byte.Parse("1");
            int acc = 0;
            int multipleOf2 = 1;
            if ((tempB & one) == one)
            {
                acc += multipleOf2;
            }

            multipleOf2 *= 2;
            if ((tempG & one) == one)
            {
                acc += multipleOf2;
            }

            multipleOf2 *= 2;
            if ((tempR & one) == one)
            {
                acc += multipleOf2;
            }

            multipleOf2 *= 2;
            one = byte.Parse("2");
            if ((tempB & one) == one)
            {
                acc += multipleOf2;
            }

            multipleOf2 *= 2;
            if ((tempG & one) == one)
            {
                acc += multipleOf2;
            }

            multipleOf2 *= 2;
            if ((tempR & one) == one)
            {
                acc += multipleOf2;
            }

            multipleOf2 *= 2;
            one = byte.Parse("4");
            if ((tempB & one) == one)
            {
                acc += multipleOf2;
            }

            multipleOf2 *= 2;
            if ((tempG & one) == one)
            {
                acc += multipleOf2;
            }

            multipleOf2 *= 2;
            if ((tempR & one) == one)
            {
                acc += multipleOf2;
            }

            multipleOf2 *= 2;
            one = byte.Parse("8");
            if ((tempB & one) == one)
            {
                acc += multipleOf2;
            }

            multipleOf2 *= 2;
            if ((tempG & one) == one)
            {
                acc += multipleOf2;
            }

            multipleOf2 *= 2;
            if ((tempR & one) == one)
            {
                acc += multipleOf2;
            }

            multipleOf2 *= 2;
            one = byte.Parse("16");
            if ((tempB & one) == one)
            {
                acc += multipleOf2;
            }

            multipleOf2 *= 2;
            if ((tempG & one) == one)
            {
                acc += multipleOf2;
            }

            multipleOf2 *= 2;
            if ((tempR & one) == one)
            {
                acc += multipleOf2;
            }

            multipleOf2 *= 2;
            one = byte.Parse("32");
            if ((tempB & one) == one)
            {
                acc += multipleOf2;
            }

            multipleOf2 *= 2;
            if ((tempG & one) == one)
            {
                acc += multipleOf2;
            }

            multipleOf2 *= 2;
            if ((tempR & one) == one)
            {
                acc += multipleOf2;
            }

            multipleOf2 *= 2;
            one = byte.Parse("64");
            if ((tempB & one) == one)
            {
                acc += multipleOf2;
            }

            multipleOf2 *= 2;
            if ((tempG & one) == one)
            {
                acc += multipleOf2;
            }

            multipleOf2 *= 2;
            if ((tempR & one) == one)
            {
                acc += multipleOf2;
            }

            multipleOf2 *= 2;
            one = byte.Parse("128");
            if ((tempB & one) == one)
            {
                acc += multipleOf2;
            }

            multipleOf2 *= 2;
            if ((tempG & one) == one)
            {
                acc += multipleOf2;
            }

            multipleOf2 *= 2;
            if ((tempR & one) == one)
            {
                acc += multipleOf2;
            }

            this.BitMixValue = acc;
        }

        /// <summary>
        /// Gets the bit mix value.
        /// </summary>
        public int BitMixValue
        {
            get;
            private set;
        }

        /// <summary>
        /// Gets or sets the red.
        /// </summary>
        /// <value>
        /// The red.
        /// </value>
        public double Red
        {
            get;
            set;
        }

        /// <summary>
        /// Gets or sets the green.
        /// </summary>
        /// <value>
        /// The green.
        /// </value>
        public double Green
        {
            get;
            set;
        }

        /// <summary>
        /// Gets or sets the blue.
        /// </summary>
        /// <value>
        /// The blue.
        /// </value>
        public double Blue
        {
            get;
            set;
        }
    }
}
